#Rem
Header: AGFX ASSERT global functions. 
#End

Strict

#Rem
	summary: Assertion default message.	
#End
Const ASSERT_MESSAGE$ = "Assertion failed!"

#Rem
	summary: Assertion functions.
	Call the corresponding Assert function with the check that you expect to pass.  If it fails, the error message will be thrown.
#End
Function Assert:Void(val?, msg$=ASSERT_MESSAGE)
	If Not val Then AssertError(msg)
End
#Rem
	summary: Assertion for Null.	
#End
Function AssertNull:Void(val:Object, msg$=ASSERT_MESSAGE)
	If val <> Null Then AssertError(msg)
End
#Rem
	summary: Assertion for Not Null.	
#End
Function AssertNotNull:Void(val:Object, msg$=ASSERT_MESSAGE)
	If val = Null Then AssertError(msg)
End

#Rem
	summary: Assertion for Int equals.	
#End
Function AssertEqualsInt:Void(val%, expected%, msg$=ASSERT_MESSAGE)
	If val <> expected Then AssertError(msg + " " + val + "<>"+expected)
End
#Rem
	summary: Assertion for Float equals.	
#End
Function AssertEqualsFloat:Void(val#, expected#, msg$=ASSERT_MESSAGE)
	If val <> expected Then AssertError(msg + " " + val + "<>"+expected)
End
#Rem
	summary: Assertion for string equals.	
#End
Function AssertEqualsString:Void(val$, expected$, msg$=ASSERT_MESSAGE)
	If val <> expected Then AssertError(msg + " " + val + "<>"+expected)
End

#Rem
	summary: Assertion for Case.	
	val<>expected
#End
Function AssertEqualsIgnoreCase:Void(val$, expected$, msg$=ASSERT_MESSAGE)
	' TODO: optimise this (does it create new objects?)
	If val.ToLower() <> expected.ToLower() Then AssertError(msg + " " + val + "<>"+expected)
End

#Rem
	summary: Assertion for Not Int equals.	
#End
Function AssertNotEqualInt:Void(val%, expected%, msg$=ASSERT_MESSAGE)
	If val = expected Then AssertError(msg + " " + val + "="+expected)
End
#Rem
	summary: Assertion for Not Float equals.	
#End
Function AssertNotEqualFloat:Void(val#, expected#, msg$=ASSERT_MESSAGE)
	If val = expected Then AssertError(msg + " " + val + "="+expected)
End

#Rem
	summary: Assertion for Not String equals.	
#End
Function AssertNotEqualString:Void(val$, expected$, msg$=ASSERT_MESSAGE)
	If val = expected Then AssertError(msg + " " + val + "="+expected)
End

#Rem
	summary: Assertion for Not Case equals.	
#End
Function AssertNotEqualIgnoreCase:Void(val$, expected$, msg$=ASSERT_MESSAGE)
	' TODO:
End

#Rem
	summary: Assertion for less Int.	
#End
Function AssertLessThanInt:Void(val%, expected%, msg$=ASSERT_MESSAGE)
	If val >= expected Then AssertError(msg + " " + val + ">="+expected)
End

#Rem
	summary: Assertion for less Float.	
#End
Function AssertLessThanFloat:Void(val#, expected#, msg$=ASSERT_MESSAGE)
	If val >= expected Then AssertError(msg + " " + val + ">="+expected)
End

#Rem
	summary: Assertion for greater Int.	
#End
Function AssertGreaterThanInt:Void(val%, expected%, msg$=ASSERT_MESSAGE)
	If val <= expected Then AssertError(msg + " " + val + "<="+expected)
End

#Rem
	summary: Assertion for greater Float.	
#End
Function AssertGreaterThanFloat:Void(val#, expected#, msg$=ASSERT_MESSAGE)
	If val <= expected Then AssertError(msg + " " + val + "<="+expected)
End

#Rem
	summary: Assertion for greater or less Int.	
#End
Function AssertLessThanOrEqualInt:Void(val%, expected%, msg$=ASSERT_MESSAGE)
	If val > expected Then AssertError(msg + " " + val + ">"+expected)
End

#Rem
	summary: Assertion for greater or less Float.	
#End
Function AssertLessThanOrEqualFloat:Void(val#, expected#, msg$=ASSERT_MESSAGE)
	If val > expected Then AssertError(msg + " " + val + ">"+expected)
End

#Rem
	summary: Assertion for greater or equals Int.	
#End
Function AssertGreaterThanOrEqualInt:Void(val%, expected%, msg$=ASSERT_MESSAGE)
	If val < expected Then AssertError(msg + " " + val + "<"+expected)
End

#Rem
	summary: Assertion for greater or equals Float.	
#End
Function AssertGreaterThanOrEqualFloat:Void(val#, expected#, msg$=ASSERT_MESSAGE)
	If val < expected Then AssertError(msg + " " + val + "<"+expected)
End

#Rem
	summary: Assertion for Int range.	
#End
Function AssertRangeInt:Void(val%, minbound%, maxbound%, msg$=ASSERT_MESSAGE)
	If val < minbound Or val >= maxbound Then AssertError(msg + " " + val + " is not " + minbound + "<=val<" + size)
End

#Rem
	summary: Assertion for Float range.	
#End
Function AssertRangeFloat:Void(val#, minbound#, maxbound#, msg$=ASSERT_MESSAGE)
	If val < minbound Or val >= maxbound Then AssertError(msg + " " + val + " is not " + minbound + "<=val<" + size)
End

#Rem
	summary: Assertion for Int out of range.	
#End
Function AssertRangeInclusiveInt:Void(val%, minbound%, maxbound%, msg$=ASSERT_MESSAGE)
	If val < minbound Or val > maxbound Then AssertError(msg + " " + val + " is not " + minbound + "<=val<=" + size)
End

#Rem
	summary: Assertion for Float out of range.	
#End
Function AssertRangeInclusiveFloat:Void(val#, minbound#, maxbound#, msg$=ASSERT_MESSAGE)
	If val < minbound Or val > maxbound Then AssertError(msg + " " + val + " is not " + minbound + "<=val<=" + size)
End

#Rem
	summary: Print Assertion and show error message.	
#End
Function AssertError:Void(msg:String)
	Print(msg)
	Error(msg)
End

